home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / README.Linux_OSS_bufsize < prev    next >
Text File  |  2000-05-16  |  3KB  |  48 lines

  1. The following was copied from OSS Programmer's Guide 
  2. http://www.opensound.com/pguide/index.html
  3. -------------------------------------------------------------------------
  4. http://www.opensound.com/pguide/audio2.html
  5. Section "Buffering - Improving real time performance":
  6.  
  7. Buffering parameters
  8.  
  9. In some cases it may be desirable to select the fragment size explicitly.
  10. For example in real time applications (such as games) it is necessary to
  11. use relatively short fragments. Otherwise delays between events on the
  12. screen and their associated sound effects become too long. OSS API
  13. contains an ioctl call for setting the fragment size and maximum number of
  14. fragments.
  15.  
  16.      int arg = 0xMMMMSSSS;
  17.  
  18.      if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &arg)) error();
  19.  
  20. Argument of this call is an integer encoded as 0xMMMMSSSS (in hex). The 16
  21. least significant bits determine the fragment size. The size is 2SSSS. For
  22. example SSSS=0008 gives fragment size of 256 bytes (28). The minimum is 16
  23. bytes (SSSS=4) and the maximum is total_buffer_size/2. Some devices or
  24. processor architectures may require larger fragments in this case the
  25. requested fragment size is automatically increased.  The 16 most
  26. significant bits (MMMM) determine maximum number of fragments. By default
  27. the deriver computes this based on available buffer space. The minimum
  28. value is 2 and the maximum depends on the situation. Set MMMM=0x7fff if
  29. you don't want to limit the number of fragments.
  30.  
  31. NOTE! This ioctl call must be used as early as possible. The optimum
  32. location is immediately after opening the device. It is NOT possible to
  33. change fragmenting parameters second time without closing and reopening
  34. the device. Also note that calling read(), write() or the above three
  35. ioctl calls "locks" the buffering parameters which may not be changed
  36. after that.
  37.  
  38. NOTE2! Setting the fragment size and/or number of fragments too small may
  39. have unexpected results (at least in slow machines). UNIX is multitasking
  40. environment where other processes may use CPU time unexpectedly. The
  41. application must ensure that the selected fragmenting parameters provide
  42. enough "slack" so that other concurrently running processes don't cause
  43. underruns. Each underrun causes a click or pause to the output signal.
  44. With relatively short fragments this may cause whining sound which is very
  45. difficult to identify. Using fragment sizes shorter than 256 bytes is not
  46. recommended as the default mode of application. Short fragments should
  47. only be used when explicitly requested by user.
  48.